package com.ynet.middleground.riskmanage.mq.consumer;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.entity.WorldexBlchIn;
import com.ynet.middleground.riskmanage.entity.WorldexBlchOut;
import com.ynet.middleground.riskmanage.model.worldex.WorldexModel;
import com.ynet.middleground.riskmanage.mq.SinkBlch;
import com.ynet.middleground.riskmanage.mq.producer.BlchProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author liulx
 * @description 保理池业务接收处理
 * @date 2020-08-20 14:42
 */
@Component
public class BlchConsumer {

    @Autowired
    private WorldexModel worldexModel;

    @Autowired
    private BlchProducer blchProducer;

    /**
     * 接收保理池入池数据
     *
     * @param data 全球捷运推送过来的入池数据
     */
    @StreamListener(SinkBlch.QQJY_TO_JKZTFK_BLCH_IN)
    public void inputBlchInConsumer(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 接收入池数据，从 Binding-{}收到信息-{}", SinkBlch.QQJY_TO_JKZTFK_BLCH_IN, data);
        WorldexBlchIn worldexBlchIn = worldexModel.saveBlchIn(data);
        data.put("id", worldexBlchIn.getId());
        blchProducer.sendMessagesBlchIn(data);
    }

    /**
     * 接收保理池出池数据
     *
     * @param data 全球捷运推送过来的出池数据
     */
    @StreamListener(SinkBlch.QQJY_TO_JKZTFK_BLCH_OUT)
    public void inputBlchOutConsumer(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 接收出池数据，从 Binding-{}收到信息-{}", SinkBlch.QQJY_TO_JKZTFK_BLCH_OUT, data);
        WorldexBlchOut worldexBlchOut = worldexModel.saveBlchOut(data);
        data.put("id", worldexBlchOut.getId());
        blchProducer.sendMessagesBlchOut(data);
    }

}
